home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / Miro_Downloader.exe / test / subscriptiontest.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-11-12  |  10.7 KB  |  144 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. import os
  5. import unittest
  6. import subscription
  7. from test.framework import DemocracyTestCase
  8. SAMPLE_RSS_SUBSCRIPTION_URL_1 = 'http://www.domain-1.com/videos/rss.xml'
  9. SAMPLE_RSS_SUBSCRIPTION_URL_2 = 'http://www.domain-2.com/videos/rss.xml'
  10. SAMPLE_ATOM_SUBSCRIPTION_URL_1 = 'http://www.domain-1.com/videos/atom.xml'
  11. SAMPLE_ATOM_SUBSCRIPTION_URL_2 = 'http://www.domain-2.com/videos/atom.xml'
  12. INVALID_CONTENT_1 = u'\nThis is not XML...\n'
  13. INVALID_CONTENT_2 = u'<?xml version="1.0" encoding="UTF-8" ?>\n<this-is-bogus-xml-syntax>\n    yes indeed\n</this-is-bogus-xml-syntax>\n'
  14. ATOM_LINK_CONSTRUCT_IN_RSS = u'<?xml version="1.0" encoding="UTF-8" ?>\n<rss version="2.0">\n    <channel>\n        <title>Dummy RSS Feed</title>\n        <link>http://www.getdemocracy.com</link>\n        <description>A dummy RSS feed to test USM subscription</description>\n        <atom:link \n            xmlns:atom="http://www.w3.org/2005/Atom"\n            rel="self" \n            type="application/rss+xml" \n            title="Sample Dummy RSS Feed" \n            href="%s" />\n    </channel>\n</rss>\n' % SAMPLE_RSS_SUBSCRIPTION_URL_1
  15. ATOM_LINK_CONSTRUCT_IN_ATOM = u'<?xml version="1.0" encoding="UTF-8" ?>\n<feed xmlns="http://www.w3.org/2005/Atom">\n    <title>Dummy Atom Feed</title>\n    <updated>2006-05-28T11:00:00Z</updated>\n    <author><name>Luc Heinrich</name></author>\n    <id>urn:uuid:D7732206-B0BF-4FAF-B2CE-FC25C6C5548F</id>\n    <link \n        xmlns:atom="http://www.w3.org/2005/Atom"\n        rel="self" \n        type="application/rss+xml" \n        title="Sample Dummy Atom Feed" \n        href="%s" />\n</feed>\n' % SAMPLE_ATOM_SUBSCRIPTION_URL_1
  16. REFLEXIVE_AUTO_DISCOVERY_IN_RSS = u'<?xml version="1.0" encoding="UTF-8" ?>\n<rss version="2.0">\n    <channel>\n        <title>Dummy RSS Feed</title>\n        <description>\n            A dummy RSS feed to test USM Reflexive Auto Discovery\n        </description>\n        <link>reflexive-auto-discovery-page-rss.html</link>\n    </channel>\n</rss>\n'
  17. REFLEXIVE_AUTO_DISCOVERY_PAGE_RSS_FILENAME = 'reflexive-auto-discovery-page-rss.html'
  18. REFLEXIVE_AUTO_DISCOVERY_PAGE_RSS = u'<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" \n\t                  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n\t<head>\n\t\t<meta http-equiv="Content-type" content="text/html; charset=utf-8" />\n\t\t<title>Reflexive Auto Discovery Page</title>\n\t    <link rel="alternate" type="application/rss+xml" title="RSS" href="%s" />\n\t</head>\n\t<body>\n\t    This place intentionally (almost) blank... :)\n\t</body>\n</html>\n' % SAMPLE_RSS_SUBSCRIPTION_URL_1
  19. REFLEXIVE_AUTO_DISCOVERY_IN_ATOM = u'<?xml version="1.0" encoding="UTF-8" ?>\n<feed xmlns="http://www.w3.org/2005/Atom">\n    <title>Dummy Atom Feed</title>\n    <updated>2006-05-28T11:00:00Z</updated>\n    <author><name>Luc Heinrich</name></author>\n    <id>urn:uuid:D7732206-B0BF-4FAF-B2CE-FC25C6C5548F</id>\n    <link \n        xmlns:atom="http://www.w3.org/2005/Atom"\n        rel="alternate" \n        type="application/atom+xml" \n        title="Sample Dummy AutoDiscovery Feed" \n        href="reflexive-auto-discovery-page-atom.html" />\n</feed>\n'
  20. REFLEXIVE_AUTO_DISCOVERY_PAGE_ATOM_FILENAME = 'reflexive-auto-discovery-page-atom.html'
  21. REFLEXIVE_AUTO_DISCOVERY_PAGE_ATOM = u'<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" \n\t                  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n\t<head>\n\t\t<meta http-equiv="Content-type" content="text/html; charset=utf-8" />\n\t\t<title>Reflexive Auto Discovery Page</title>\n\t    <link rel="alternate" type="application/atom+xml" title="RSS" href="%s" />\n\t</head>\n\t<body>\n\t    This place intentionally (almost) blank... :)\n\t</body>\n</html>\n' % SAMPLE_ATOM_SUBSCRIPTION_URL_1
  22. OPML_FLAT = u'<?xml version="1.0" encoding="utf-8"?>\n<opml version="1.0">\n    <head>\n        <title>Sample OPML Flat Subscription List</title>\n    </head>\n    <body>\n        <outline text="Sample Dummy RSS Feed 1" type="rss" xmlUrl="%s" />\n        <outline text="Sample Dummy Atom Feed 1" type="rss" xmlUrl="%s" />\n        <outline text="Sample Dummy RSS Feed 2" type="rss" xmlUrl="%s" />\n        <outline text="Sample Dummy Atom Feed 2" type="rss" xmlUrl="%s" />\n    </body>\n</opml>\n' % (SAMPLE_RSS_SUBSCRIPTION_URL_1, SAMPLE_ATOM_SUBSCRIPTION_URL_1, SAMPLE_RSS_SUBSCRIPTION_URL_2, SAMPLE_ATOM_SUBSCRIPTION_URL_2)
  23. OPML_NESTED = u'<?xml version="1.0" encoding="utf-8"?>\n<opml version="1.0">\n    <head>\n        <title>Sample OPML Flat Subscription List</title>\n    </head>\n    <body>\n        <outline text="folder 1">\n            <outline text="Sample Dummy RSS Feed 1" type="rss" xmlUrl="%s" />\n            <outline text="folder1-1">\n                <outline text="Sample Dummy Atom Feed 1" type="rss" xmlUrl="%s" />\n            </outline>\n        </outline>\n        <outline text="folder 2">\n            <outline text="folder2-1">\n                <outline text="Sample Dummy RSS Feed 2" type="rss" xmlUrl="%s" />\n            </outline>\n            <outline text="Sample Dummy Atom Feed 2" type="rss" xmlUrl="%s" />\n        </outline>\n    </body>\n</opml>\n' % (SAMPLE_RSS_SUBSCRIPTION_URL_1, SAMPLE_ATOM_SUBSCRIPTION_URL_1, SAMPLE_RSS_SUBSCRIPTION_URL_2, SAMPLE_ATOM_SUBSCRIPTION_URL_2)
  24.  
  25. class TestSubscription(DemocracyTestCase):
  26.     subscription.reflexiveAutoDiscoveryOpener = open
  27.     
  28.     def testInvalidSubscriptions(self):
  29.         urls = subscription.parseFile('this-file-does-not-exist.xml')
  30.         self.assert_(urls is None)
  31.         urls = subscription.parseContent(INVALID_CONTENT_1)
  32.         self.assert_(urls is None)
  33.         urls = subscription.parseContent(INVALID_CONTENT_2)
  34.         self.assert_(urls is None)
  35.  
  36.     
  37.     def testAtomLinkConstructInRSS(self):
  38.         urls = subscription.parseContent(ATOM_LINK_CONSTRUCT_IN_RSS)
  39.         self.assert_(len(urls) == 1)
  40.         self.assert_(urls[0] == SAMPLE_RSS_SUBSCRIPTION_URL_1)
  41.  
  42.     
  43.     def testAtomLinkConstructInAtom(self):
  44.         urls = subscription.parseContent(ATOM_LINK_CONSTRUCT_IN_ATOM)
  45.         self.assert_(len(urls) == 1)
  46.         self.assert_(urls[0] == SAMPLE_ATOM_SUBSCRIPTION_URL_1)
  47.  
  48.     
  49.     def testReflexiveAutoDiscoveryInRSS(self):
  50.         pageFile = file(REFLEXIVE_AUTO_DISCOVERY_PAGE_RSS_FILENAME, 'w')
  51.         pageFile.write(REFLEXIVE_AUTO_DISCOVERY_PAGE_RSS)
  52.         pageFile.close()
  53.         urls = subscription.parseContent(REFLEXIVE_AUTO_DISCOVERY_IN_RSS)
  54.         self.assert_(len(urls) == 1)
  55.         self.assert_(urls[0] == SAMPLE_RSS_SUBSCRIPTION_URL_1)
  56.         os.remove(REFLEXIVE_AUTO_DISCOVERY_PAGE_RSS_FILENAME)
  57.  
  58.     
  59.     def testReflexiveAutoDiscoveryInAtom(self):
  60.         pageFile = file(REFLEXIVE_AUTO_DISCOVERY_PAGE_ATOM_FILENAME, 'w')
  61.         pageFile.write(REFLEXIVE_AUTO_DISCOVERY_PAGE_ATOM)
  62.         pageFile.close()
  63.         urls = subscription.parseContent(REFLEXIVE_AUTO_DISCOVERY_IN_ATOM)
  64.         self.assert_(len(urls) == 1)
  65.         self.assert_(urls[0] == SAMPLE_ATOM_SUBSCRIPTION_URL_1)
  66.         os.remove(REFLEXIVE_AUTO_DISCOVERY_PAGE_ATOM_FILENAME)
  67.  
  68.     
  69.     def testFlatOPMLSubscriptions(self):
  70.         urls = subscription.parseContent(OPML_FLAT)
  71.         self.assert_(len(urls) == 4)
  72.         self.assert_(urls[0] == SAMPLE_RSS_SUBSCRIPTION_URL_1)
  73.         self.assert_(urls[1] == SAMPLE_ATOM_SUBSCRIPTION_URL_1)
  74.         self.assert_(urls[2] == SAMPLE_RSS_SUBSCRIPTION_URL_2)
  75.         self.assert_(urls[3] == SAMPLE_ATOM_SUBSCRIPTION_URL_2)
  76.  
  77.     
  78.     def testNestedOPMLSubscriptions(self):
  79.         urls = subscription.parseContent(OPML_NESTED)
  80.         self.assert_(len(urls) == 4)
  81.         self.assert_(urls[0] == SAMPLE_RSS_SUBSCRIPTION_URL_1)
  82.         self.assert_(urls[1] == SAMPLE_ATOM_SUBSCRIPTION_URL_1)
  83.         self.assert_(urls[2] == SAMPLE_RSS_SUBSCRIPTION_URL_2)
  84.         self.assert_(urls[3] == SAMPLE_ATOM_SUBSCRIPTION_URL_2)
  85.  
  86.  
  87.  
  88. class TestFindSubscribeLinks(DemocracyTestCase):
  89.     
  90.     def testDifferstHost(self):
  91.         url = 'http://youtoob.com'
  92.         self.assertEquals(subscription.findSubscribeLinks(url), ('none', []))
  93.  
  94.     
  95.     def testNoLinks(self):
  96.         url = 'http://subscribe.getdemocracy.com/'
  97.         self.assertEquals(subscription.findSubscribeLinks(url), ('feed', []))
  98.  
  99.     
  100.     def testLinkInPath(self):
  101.         url = 'http://subscribe.getdemocracy.com/http%3A//www.myblog.com/rss'
  102.         self.assertEquals(subscription.findSubscribeLinks(url), ('feed', [
  103.             'http://www.myblog.com/rss']))
  104.  
  105.     
  106.     def testLinkInQuery(self):
  107.         url = 'http://subscribe.getdemocracy.com/?url1=http%3A//www.myblog.com/rss'
  108.         self.assertEquals(subscription.findSubscribeLinks(url), ('feed', [
  109.             'http://www.myblog.com/rss']))
  110.  
  111.     
  112.     def testMultipleLinksInQuery(self):
  113.         url = 'http://subscribe.getdemocracy.com/?url1=http%3A//www.myblog.com/rss&url2=http%3A//www.yourblog.com/atom&url3=http%3A//www.herblog.com/scoobydoo'
  114.         (type, links) = subscription.findSubscribeLinks(url)
  115.         self.assertEquals(type, 'feed')
  116.         self.assertEquals(set(links), set([
  117.             'http://www.myblog.com/rss',
  118.             'http://www.yourblog.com/atom',
  119.             'http://www.herblog.com/scoobydoo']))
  120.  
  121.     
  122.     def testQueryGarbage(self):
  123.         url = 'http://subscribe.getdemocracy.com/?url1=http%3A//www.myblog.com/rss&url2=http%3A//www.yourblog.com/atom&url3=http%3A//www.herblog.com/scoobydoo&foo=bar&extra=garbage'
  124.         (type, links) = subscription.findSubscribeLinks(url)
  125.         self.assertEquals(type, 'feed')
  126.         self.assertEquals(set(links), set([
  127.             'http://www.myblog.com/rss',
  128.             'http://www.yourblog.com/atom',
  129.             'http://www.herblog.com/scoobydoo']))
  130.  
  131.     
  132.     def testChannelGuideLinks(self):
  133.         url = 'http://subscribe.getdemocracy.com/channelguide.php?url1=http%3A//www.mychannelguide.com/'
  134.         self.assertEquals(subscription.findSubscribeLinks(url), ('guide', [
  135.             'http://www.mychannelguide.com/']))
  136.  
  137.     
  138.     def testDownloadLinks(self):
  139.         url = 'http://subscribe.getdemocracy.com/download.php?url1=http%3A//www.myblog.com/videos/cats.ogm'
  140.         self.assertEquals(subscription.findSubscribeLinks(url), ('download', [
  141.             'http://www.myblog.com/videos/cats.ogm']))
  142.  
  143.  
  144.